from pytest import fixture
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager
from data.user import User
from pages import AuthenticationPage


@fixture(scope="function")
def browser():
    firefox_browser = browser_builder()
    yield firefox_browser
    firefox_browser.quit()


def browser_builder():
    s = Service(GeckoDriverManager().install())
    firefox_browser = webdriver.Firefox(service=s)
    return firefox_browser


@fixture(scope="module")
def profile_page(user):
    profile_page = AuthenticationPage(driver=browser_builder())\
        .go_to_site(url=AuthenticationPage.URL)\
        .input_login(user.login)\
        .input_password(user.password)
    return profile_page


@fixture(scope="function")
def login_page(browser):
    auth_page = AuthenticationPage(driver=browser).go_to_site(url=AuthenticationPage.URL)
    return auth_page


@fixture(scope="module")
def non_existing_user():
    user = User(login="WhoAmIiDoNtKnow1",
                password="QWerty123",
                firstname="ЭрикЭриксон",
                lastname="Петров",
                secret="кросаут")

    return user


@fixture(scope="module")
def user():
    user = User(login="jojo.djonson",
                password="!Qwerty123",
                firstname="Джо",
                lastname="Джонсон",
                secret="гта")

    return user
